package data

import (
	"context"
	"github.com/go-kratos/kratos/v2/log"
	"maintenance_fund/internal/biz"
	"maintenance_fund/pkg/security"
)

type SystemUserRepo struct {
	data *Data
	log  *log.Helper
}

func NewSystemUserRepo(data *Data, logger log.Logger) biz.SysUserRepo {
	return &SystemUserRepo{
		data: data,
		log:  log.NewHelper(logger),
	}
}

func (s *SystemUserRepo) Save(ctx context.Context, user *biz.SysUser) error {
	encryptPassword, err := security.EncryptPassword(user.UserPassword)
	if err != nil {
		return err
	}

	return s.data.db.SysUser.Create().
		SetUserPassword(encryptPassword).
		SetUserName(user.UserName).
		SetNickName(user.NickName).
		SetPhone(user.Phone).
		SetProvinceCode(user.ProvinceCode).
		SetCityCode(user.CityCode).
		SetAreaCode(user.AreaCode).
		SetStatus("enable").
		Exec(ctx)
}

func (s *SystemUserRepo) Update(ctx context.Context, user *biz.UpdateUser) error {
	//TODO implement me
	panic("implement me")
}

func (s *SystemUserRepo) Delete(ctx context.Context, i int32) error {
	//TODO implement me
	panic("implement me")
}

func (s *SystemUserRepo) Get(ctx context.Context, i int32) (*biz.SysUser, error) {
	//TODO implement me
	panic("implement me")
}

func (s *SystemUserRepo) ListByCondition(ctx context.Context, condition *biz.SearchCondition) ([]*biz.SysUser, error) {
	//TODO implement me
	panic("implement me")
}
